<template>
    <view>
        <view class="tabbar-container" :class="isIpx?'IpxBot':''">
            <view class="tabbar-item" v-for="(item,index) in tabList" :class="[item.centerItem ? 'center-item' : '']"
                @click="changeItem(item)" :key="index">
                <view class="item-top" :style="{padding: item.id == '2'? 0 :'8rpx'}">
                    <image :src="tabId==item.id?item.selectIcon:item.icon" mode=""></image>
                </view>
                <view class="item-bottom" :class="[tabId==item.id ? 'item-active' : '']">
                    <text>{{item.text}}</text>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        props: {
            currentPage: {
                type: Number,
                default: 0
            }
        },
        data() {
            return {
                //适配IPhoneX
                isIpx: false, 
                //底部Tab
                tabId: 0,
                tabList: [{
                    id: 0,
                    path: "/pages/view/homepage/homepage",
                    icon: "/static/hpb.png",
                    selectIcon: "/static/hpr.png",
                    text: "首页",
                    centerItem: false
                }, {
                    id: 1,
                    path: "/pages/view/activity/activity",
                    icon: "/static/acb.png",
                    selectIcon: "/static/acr.png",
                    text: "活动",
                    centerItem: false
                }, {
                    id: 2,
                    path: "/pages/view/add/add",
                    icon: "/static/addy.png",
                    selectIcon: "/static/addy.png",
					text:'新增',
                    centerItem: true
                }, {
                    id: 3,
                    path: "/pages/view/team/team",
                    icon: "/static/tdb.png",
                    selectIcon: "/static/tdr.png",
                    text: "团队",
                    centerItem: false
                }, {
                    id: 4,
                    path: "/pages/view/personal/personal",
                    icon: "/static/myb.png",
                    selectIcon: "/static/myr.png",
                    text: "我的",
                    centerItem: false
                }],
            };
        },
        mounted() {
            this.tabId = this.currentPage;
            //隐藏原生tab
            uni.hideTabBar();
        },
        created() {
            // 判断为 iPhone X 给予底部距离
            let that = this
            uni.getSystemInfo({
                success: function(res) {
                    if (res.model.indexOf('iPhone X') !== -1) {
                        that.isIpx = true;
                    }
                }
            })
        },
        methods: {
            // tab 切换
            changeItem(item) {
                if (item.id == 2) {
                    uni.switchTab({
                        url: item.path,
                    });
                } else {
                    uni.switchTab({
                        url: item.path,
                    });
                }
            },

        }
    }
</script>
<style scoped>
    view {
        padding: 0;
        margin: 0;
        box-sizing: border-box;
    }

    .tabbar-container {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        /* height: 100rpx; */
        box-shadow: 0 0 5px #999;
        display: flex;
        align-items: center;
        padding: 5rpx 0;
        color: #999999;
        background-color: #FFFFFF;
    }

    .tabbar-container .tabbar-item {
        width: 20%;
        height: 100rpx;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        text-align: center;
    }

    .tabbar-container .item-active {
        color: #d81e06;
    }

    .tabbar-container .center-item {
        display: block;
        position: relative;
    }

    .tabbar-container .tabbar-item .item-top {
        width: 70rpx;
        height: 70rpx;
        padding: 5rpx;
    }

    .tabbar-container .center-item .item-top {
        flex-shrink: 0;
        width: 130rpx;
        height: 130rpx;
        position: absolute;
        top: -67rpx;
        left: calc(50% - 70rpx);
        border-radius: 50%;
        background-color: #FFFFFF;
    }

    .tabbar-container .tabbar-item .item-top image {
        width: 100%;
        height: 100%;
    }

    .tabbar-container .tabbar-item .item-bottom {
        font-size: 25rpx;
        width: 100%;
    }

    .tabbar-container .center-item .item-bottom {
        position: absolute;
        bottom: 2rpx;
    }

    /* 适配iPhone X */
    .IpxBot {
        padding-bottom: 30rpx !important;
    }
</style>
